/*
 * @(#) RoleInterceptor.java 2011-9-20
 *
 * Copyright (c) 2011, Strong Technology. All Rights Reserved.
 * Strong Technology. CONFIDENTIAL
 */
package cn.strong.gweva.common.interceptor;

import java.util.Map;

import cn.strong.gweva.common.business.entity.LoginEntity;
import cn.strong.gweva.common.presentation.action.BaseAction;
import cn.strong.gweva.common.util.Constants;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 验证角色权限
 * 
 * @author lilanfei
 * @version 1.0
 * @since 2011-9-20
 */
public class RoleInterceptor extends AbstractInterceptor
{

	/**  */
	private static final long serialVersionUID = 6600084168317628467L;

	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public String intercept(ActionInvocation invocation) throws Exception
	{
		Map map = invocation.getInvocationContext().getSession();

		//判断session中是否有登陆信息
		if(map.get(Constants.SESSION_LOGIN_USER_INF) == null)
		{
			return Action.LOGIN;
		}
		else
		{
			LoginEntity loginUser = (LoginEntity)map.get(Constants.SESSION_LOGIN_USER_INF);
			if (!loginUser.getIsAdmin())
			{
				// 没权限
				return BaseAction.NO_PERMS;
			}
			else
			{
				//继续下一个interceptor
				return invocation.invoke();
			}
		}
	}

}
